#!/bin/bash

LOGFILE=`date +"/var/log/qrpbbb/%Y%m%d-%H%M.process"`

LOCK=/tmp/qrpbbb_process
trap 'rm -f ${LOCK} ; exit 1' 1 2 3 15

if /usr/lib/news/bin/shlock -p $$ -f ${LOCK}
then
    /root/qrpbbb/qrpbbb_process.py 2>&1 >${LOGFILE}
    # still has an interactive routine
    echo | /root/qrpbbb/qrpbbb_queuecheck.py 2>&1 >>${LOGFILE}

    # if nothing interesting, remove
    n=`cat ${LOGFILE}|egrep -v "^qrpbbb"\|"^Removing"\|"contentash"\|"^Still"\|"^Remaining"\|"^Packets"\|"^$"|wc -l`
    if [ "x"$n == "x0" ]; then rm -f ${LOGFILE}; fi
fi
rm -f ${LOCK}
